<template>
  <el-form style="width:40%;" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="编号" prop="id">
      <el-input v-model="ruleForm.id" :disabled="true"></el-input>
    </el-form-item>

    <el-form-item label="用户编号" prop="user_id">
      <el-input v-model="ruleForm.user_id" :disabled="true"></el-input>
    </el-form-item>

    <el-form-item label="购物车编号" prop="cars_id">
      <el-input v-model="ruleForm.cars_id" :disabled="true"></el-input>
    </el-form-item>

    <el-form-item label="昵称" prop="nickname">
      <el-input v-model="ruleForm.nickname"></el-input>
    </el-form-item>

    <el-form-item label="性别" prop="sex">
      <el-input v-model="ruleForm.sex"></el-input>
    </el-form-item>

    <el-form-item label="电话" prop="phone">
      <el-input v-model="ruleForm.phone"></el-input>
    </el-form-item>

    <el-form-item label="邮编" prop="post">
      <el-input v-model="ruleForm.post"></el-input>
    </el-form-item>

    <el-form-item label="地址" prop="address">
      <el-input v-model="ruleForm.address"></el-input>
    </el-form-item>

    <el-form-item label="订单编号" prop="order_id">
      <el-input v-model="ruleForm.order_id" :disabled="true"></el-input>
    </el-form-item>

    <el-form-item label="订单状态" prop="order_state">
      <el-input v-model="ruleForm.order_state" :disabled="true"></el-input>
    </el-form-item>

    <el-form-item label="收货人" prop="receive">
      <el-input v-model="ruleForm.receive"></el-input>
    </el-form-item>


    <el-form-item label="备注" prop="memo">
      <el-input v-model="ruleForm.memo"></el-input>
    </el-form-item>


    <el-form-item>
      <el-button type="info" @click="cancel()">取消</el-button>
      <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  const axios = require('axios')
  export default {
    data() {
      return {
        ruleForm: {
          phone: '',
          address: ''
        },
        rules: {
        }
      };
    },
    methods: {
      submitForm(formName) {  // 修改按钮
        const _this = this
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$axios.post('http://localhost:9000/personal/save', this.ruleForm).then(function (resp) {
              console.log(resp)
              if (resp.data == 'success') {
                _this.$alert('用户编号<' + _this.ruleForm.id + '>已修改', '消息', {
                  confirmButtonText: '确定',
                  callback: action => {
                    _this.$router.push('/user/personal')
                  }
                });
              }
            });
            console.log('编号<' + _this.ruleForm.id + '>已修改')
          } else {
            return false;
          }
        })
      },
      cancel() {
        this.$router.go(-1)
        this.$message({
          type:'info',
          message:'取消修改'
        })
      }
    },
    created() {
      console.log('更新id：' + this.$route.query.id)
      const _this = this
      this.$axios.get('http://localhost:9000/personal/findById/' + this.$route.query.id).then(function (resp) {
        _this.ruleForm = resp.data
      })
    }
  }
</script>

<style scoped>

</style>
